# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface

from apps.tax_honor.tax_honor.items import NetTaxHonorItem
from apps.tax_honor.tax_honor.utils.check import CheckUtils


class TaxHonorPipeline:
    check_utils = CheckUtils()

    def process_item(self, item, spider):
        if isinstance(item, NetTaxHonorItem):
            if self.check_utils.check_company_name_is_valid(item.company_name):
                if ' ' in item.company_name:
                    item.company_name = item.company_name.replace(' ', '')
                return item
            else:
                spider.logger.error(f"company_name is invalid：{item.company_name}")
        else:
            return item
